home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so91.lha / FileName / split.c < prev   
Encoding:
C/C++ Source or Header  |  1991-10-23  |  2.7 KB  |  100 lines

  1. ;/* Split.c - AmigaMail SplitName() example.  Compiled with SAS/C 5.10a.
  2. lc -cfis -v -d0 -b0 -j73 Split.c
  3. blink from Split.o to Split lib lib:amiga.lib ; if you don't have pragmas
  4. quit
  5. * Tuesday, 16-Jul-91 12:15:49, Ewout
  6. *
  7. *
  8. */
  9. /* (c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  10. The information contained herein is subject to change without notice,
  11. and is provided "as is" without warranty of any kind, either expressed
  12. or implied.  The entire risk as to the use of this information is
  13. assumed by the user.
  14. */
  15.  
  16. #include <exec/memory.h>
  17. #include <dos/dosextens.h>
  18. #include <dos/rdargs.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/dos_protos.h>
  22.  
  23. /* def PRAGMAS if you have them */
  24. /* #define PRAGMAS */
  25. #ifdef PRAGMAS
  26. #include <pragmas/exec_pragmas.h>
  27. #include <pragmas/dos_pragmas.h>
  28. #else
  29. struct ExecBase *SysBase;
  30. struct DosLibrary *DOSBase;
  31.  
  32. #endif
  33.  
  34. #define BUFFERSIZE      128
  35.  
  36. VOID            main(VOID);
  37.  
  38. VOID
  39. main(VOID)
  40. {
  41. #ifdef PRAGMAS
  42.     struct DosLibrary *DOSBase;
  43.  
  44. #endif
  45.     struct RDArgs  *readargs;
  46.     LONG            rargs[2];
  47.     UBYTE          *filename, *buffer;
  48.     ULONG           buffersize;
  49.     WORD            position = 0;
  50.     LONG            vargs[4];
  51.  
  52. #ifndef PRAGMAS
  53.     /* set up SysBase */
  54.     SysBase = (*((struct Library **) 4));
  55. #endif
  56.  
  57.     /* Fail silently if < 37 */
  58.     if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  59.     {
  60.  
  61.         /* See the DOS Autodocs for more information about ReadArgs() */
  62.         if (readargs = ReadArgs("FILE/A,BUFFERSIZE/A/N", rargs, NULL))
  63.         {
  64.             filename = (UBYTE *) rargs[0];
  65.             buffersize = *((LONG *) rargs[1]);
  66.             if (buffersize < 1 || buffersize > 4096)
  67.                 buffersize = BUFFERSIZE;
  68.  
  69.             if (buffer = AllocMem(buffersize, MEMF_CLEAR))
  70.             {
  71.                 position = SplitName(filename, ':', buffer, position, buffersize);
  72.  
  73.                 vargs[0] = position;
  74.                 vargs[1] = (LONG) buffer;
  75.                 VFPrintf(Output(), "Devicename: position: %ld Buffer: %s\n", vargs);
  76.  
  77.                 if (position == -1)
  78.                     position = 0;
  79.  
  80.                 do
  81.                 {
  82.                     position =
  83.                         SplitName(filename, '/', buffer, position, buffersize);
  84.                     vargs[0] = position;
  85.                     vargs[1] = (LONG) buffer;
  86.                     VFPrintf(Output(),
  87.                              "Path component: position: %ld Buffer: %s\n",
  88.                              vargs);
  89.                 } while (position != -1);
  90.                 FreeMem(buffer, buffersize);
  91.             }
  92.             FreeArgs(readargs);
  93.  
  94.         }
  95.         else
  96.             PrintFault(IoErr(), NULL);
  97.         CloseLibrary((struct Library *) DOSBase);
  98.     }
  99. }
  100.